﻿@*列表页模板*@
@{
    Layout = null;
    var nodeService = new NodeService();
    var siteId =int.Parse(Request.RequestContext.RouteData.Values["pageid"].ToString());//获取分页的数字
    var maxDepth = nodeService.GetMany(n => n.SiteId == siteId)
                         .OrderByDescending(n => n.Depth)
                         .FirstOrDefault()
                         .Depth; //当前站点最大层数 author:郑利
    var Depth = maxDepth+1; //当前站点实际层级
    var siteServer = new SiteService().GetEntity(siteId);
    var childNodes = nodeService.GetMany(n=> n.SiteId == siteId && n.Depth ==0).OrderBy(n => n.Left);
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@siteServer.SiteTitle</title>
    <style>
        /*预置全局样式*/
        body,h1,h2,div,table,tr,th,td,a,input{background:transparent;font-size:100%;margin:0;padding:0;border:0;outline:0;}
        body{color:#222;font-size:14px;line-height:1.42857143;font-family:"Microsoft YaHei"}
        a{color:#222;text-decoration:none;}
        a:hover{color:red;}
        .check-list{width: 980px; margin:50px auto;}
        .check-list .hd{ margin-bottom:20px;}
        .check-list h1.title{ font-size:30px; line-height:1.75; text-align:center;}
        .check-list .th{padding:0 15px; height: 40px; background-color:#f5f5f5;}
        .check-list .th .title{line-height:40px; font-size:18px; font-weight:bold;}
        .check-list .th .btn{float: right; margin-top: 8px;}
        .check-list .th .btn span{color: #c00; margin-left: 5px;}
        .check-list .sideName{line-height: 32px; font-size: 15px; padding: 10px 0;}
        .ysqdTable{width: 100%; border-collapse: collapse;}
        .ysqdTable td{padding: 5px 10px; text-align: left; border: 1px solid #ddd; width: 100px;}
        .ysqdTable td.id{width: 40px; text-align: center;}
        .ysqdTable td.url{width: auto; word-wrap : break-word ; word-break:break-all;}
    </style>
</head>
<body>

    <div class="check-list">
        <div class="hd">
            <h1 class="title">
                <text>@siteServer.SiteTitle</text>节点目录检测清单
            </h1>
        </div>
        <div class="bd">
            <div class="th">
                <div class="btn"><button type="button" onclick="exportExl('nodeTable')">导出Excel</button></div>
                <div class="title">节点目录</div>
            </div>
            <!-- 站点链接 S -->
            <h2 class="sideName">
                <a class="a1" href="@Power.Url.SiteUrl(siteServer.Subdomain)">网站首页</a>
            </h2>
            <!-- 栏目列表 S -->
            <table class="ysqdTable" id="nodeTable">
                <tr class="title">
                    <td class="id">ID</td>
                    @for(var i = 0; i < Depth; i++)
                    {<td>@(i+1)<text>级栏目</text></td>}
                    <td class="url">栏目地址</td>
                </tr>
                @foreach (var childnode in childNodes)
                {
                    var childCount=(childnode.Right - childnode.Left -1)/2; //获取子栏目总数
                    int subDepth=childnode.Depth+1;//子栏目层级
                    string nodeUrl;
                    if (childnode.NodeType == NodeType.Link)
                    {
                        if(childnode.LinkUrl.StartsWith("http")){
                        nodeUrl = childnode.LinkUrl;
                        }
                        else if(childnode.LinkUrl.StartsWith("{Site")){
                        nodeUrl = Power.Url.NodeUrl(childnode);
                        }
                        else{
                        nodeUrl = Power.Url.SiteUrl(childnode.Site.Subdomain) + childnode.LinkUrl;;
                        }
                    }
                    else
                    {
                        nodeUrl = Power.Url.SiteUrl(childnode.Site.Subdomain) + Power.Url.NodeUrl(childnode);
                    }
                    <tr class="li1">
                        <td class="id">@childnode.NodeId</td>
                        <td>
                            <a class="a@(subDepth)" href="@nodeUrl" target="_blank">@childnode.NodeName</a>
                        </td>
                        @for(var i = 0; i < (Depth-subDepth); i++)
                        {<td></td>}
                        <td class="url"><span>@nodeUrl</span></td>
                    </tr>

                    if (childCount > 0 && subDepth < Depth)
                    {
                        <text>@Power.Partial("SiteCheck","验收清单多级节点-表格式", new { NodeIdentifier = childnode.Identifier, Depth, siteId=siteId, left=childnode.Left, right=childnode.Right, CurrentDepth = subDepth })
                        </text>
                    }
                }
            </table>
        </div>
    </div>

    <script type="text/javascript">
        //浏览器判断
        function  getExplorer() {
            var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
            var isOpera = userAgent.indexOf("Opera") > -1;  
            //判断是否Opera浏览器  
            if (isOpera) {  
              return "Opera"  
            };   
            //判断是否Firefox浏览器  
            if (userAgent.indexOf("Firefox") > -1) {  
              return "FF";  
            }   
            //判断是否chorme浏览器  
            if (userAgent.indexOf("Chrome") > -1){  
            return "Chrome";  
            }  
            //判断是否Safari浏览器  
            if (userAgent.indexOf("Safari") > -1) {  
              return "Safari";  
            }   
            //判断是否IE浏览器  
            if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {  
              return "IE";  
            }  
            //判断是否Edge浏览器  
            if (userAgent.indexOf("Trident") > -1) {  
              return "Edge";  
            }; 
        }
        //IE浏览器导出Excel的js
        function exportFiles(tableid)
        {

            var curTbl = document.getElementById(tableid);
            var oXL = new ActiveXObject("Excel.Application");
            var oWB = oXL.Workbooks.Add();
            var oSheet = oWB.ActiveSheet;
            var Lenr = curTbl.rows.length;
            for (i = 0; i < Lenr; i++)
            {        var Lenc = curTbl.rows(i).cells.length;
                for (j = 0; j < Lenc; j++)
                {
                    oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;

                }
            }
            oXL.Visible = true;
        }

        //谷歌浏览器 & 其他标准浏览器 导出Excel的js
        var tableToExcel = (function() {
              var uri = 'data:application/vnd.ms-excel;base64,',
              template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
                base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
                format = function(s, c) {
                    return s.replace(/{(\w+)}/g,
                    function(m, p) { return c[p]; }) }
                return function(table, name) {
                if (!table.nodeType) table = document.getElementById(table)
                var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
                window.location.href = uri + base64(format(template, ctx))
              }
            })()

        //表格导出
        function exportExl(tableid) {//整个表格拷贝到EXCEL中
            if(getExplorer()=='IE' || getExplorer()=='Edge')
            {
                exportFiles(tableid);
            }
            else
            {
                tableToExcel(tableid)
            }
        }
    </script>
</body>
</html>